<template>
  <el-form :model="merchant" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px"
    class="demo-ruleForm login-container">
    <div style="display: flex;flex-direction: row;">
      <span>
        <el-button type="primary" style="width:100%;" @click.native.prevent="cancel" :loading="logining">返回</el-button>
      </span>
      <span style="flex: 1; display: flex;justify-content: center;align-content: center;">
        <h3 class="title">商家注册</h3>
      </span>
    </div>
    <el-form-item prop="account">
      <el-input type="text" v-model="merchant.username" auto-complete="off" placeholder="账号"></el-input>
    </el-form-item>
    <el-form-item prop="checkPass">
      <el-input type="password" v-model="merchant.password" auto-complete="off" placeholder="密码"></el-input>
    </el-form-item>
    <el-form-item prop="checkPass1">
      <el-input type="password" v-model="merchant.password1" auto-complete="off" placeholder="确认密码"></el-input>
    </el-form-item>
    <el-form-item prop="phone">
      <el-input type="text" v-model="merchant.phone" :maxlength="11" auto-complete="off" placeholder="手机号码"></el-input>
    </el-form-item>
    <el-form-item style="width:100%;">

      <el-button type="primary" style="width:100%;" @click.native.prevent="register" :loading="logining">注册</el-button>
      <!--<el-button @click.native.prevent="handleReset2">重置</el-button>-->
    </el-form-item>
  </el-form>
</template>

<script>
  //import NProgress from 'nprogress'
  export default {
    data() {
      return {
        logining: false,
        merchant: {
          username: '',
          password: '',
          password1: '',
          phone: ''
        },
        
        rules2: {
          username: [
            { required: true, message: '请输入账号', trigger: 'blur' },
            //{ validator: validaePass }
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            //{ validator: validaePass2 }
          ],
          phone: [
            { required: true, message: '请输入手机号码', trigger: 'blur' },
            //{ validator: validaePass2 }
          ]
        },
      };
    },
    methods: {
      cancel() {
        this.$router.push({ path: '/login' })
      },
      register() {
        this.$refs.ruleForm2.validate((valid) => {
          if (valid) {
            if (!this.$verifyPhone(this.merchant.phone)) return
            if (this.merchant.password != this.merchant.password1) return this.$message.error("两次输入的密码不一致!")
            this.$axios({
              method:'post',
              data:this.merchant,
              url:'/merchant/register'
            }).then(r=>{
              if(r.data.err_code===0){
                this.$message.success('注册成功!')
                for(let i in this.merchant){
                    this.merchant[i]=''
                }
              }else{
                this.$message.error('用户名已存在!')
              }
            })
          } else{
            this.$message.error("请输入完整的信息!")
          }
        })
      },
      handleReset2() {
        this.$refs.ruleForm2.resetFields();
      },
      handleSubmit(){
        
        
      }

    }
  }

</script>

<style lang="scss" scoped>
  .login-container {
    /*box-shadow: 0 0px 8px 0 rgba(0, 0, 0, 0.06), 0 1px 0px 0 rgba(0, 0, 0, 0.02);*/
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;

    .title {
      margin: 0px auto 40px auto;
      text-align: center;
      color: #505458;
    }

    .remember {
      margin: 0px 0px 35px 0px;
    }
  }
</style>